﻿using Lamex.Base;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.mMachine.Common
{
    public class GetDataTable
    {
        static bool flag = false;
        public GetDataTable()
        {
            DataTable dataTable = GetMachine_SumQty();
            if (dataTable.Rows.Count > 0 && dataTable != null && dataTable.Rows[0][0].ToString() != "0")
                flag = true;
        }
        //设备类别
        public DataTable GetMachine_Type()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"SELECT 
  MACHINE_TYPE as 设备类别, 
  SUM_QTY as 数量,
  concat(cast((SUM_QTY* 100.00 / total)as decimal(18,2)), '%') as 占比
FROM 
  (
    SELECT 
      * 
    FROM 
      (
        SELECT 
          MACHINE_TYPE, 
          COUNT(1) AS SUM_QTY 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常' 
        GROUP BY 
          MACHINE_TYPE
      ) t1 
      INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1
  ) t";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备分布
        public DataTable GetMachine_Dept()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"  SELECT 
  MACHINE_USING_DEPT as 设备区域, 
  SUM_QTY as 数量,
  concat(cast((SUM_QTY* 100.00 / total)as decimal(18,2)), '%') as '占比(%)',
cast((convert(decimal(18,4),SUM_QTY) / convert(decimal(18,4),total))as decimal(18,4)) as 占比
FROM 
  (
    SELECT 
      * 
    FROM 
      (
        SELECT 
          CASE WHEN ISNULL(MACHINE_USING_DEPT,'')!='' THEN  MACHINE_USING_DEPT ELSE '未分配' END AS MACHINE_USING_DEPT,
          COUNT(1) AS SUM_QTY 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常' 
        GROUP BY 
          MACHINE_USING_DEPT
      ) t1 
      INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1
  ) t";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备投产时间
        public DataTable GetMachine_Year()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"SELECT TT.投产年份
,TT.数量
,concat(cast((TT.数量* 100.00 / total)as decimal(18,2)), '%') as '占比(%)'
,cast((convert(decimal(18,4),TT.数量) / convert(decimal(18,4),TT.total))as decimal(18,4)) as 占比
FROM (
SELECT *FROM (
SELECT * FROM (
SELECT SUM( CASE WHEN YEARS<=1 THEN QTY ELSE 0 END ) AS '<=1'
,SUM( CASE WHEN YEARS>1 AND YEARS<=3 THEN QTY ELSE 0 END ) AS '1-3(含)'
,SUM( CASE WHEN YEARS>3 AND YEARS<=5 THEN QTY ELSE 0 END ) AS '3-5(含)'
,SUM( CASE WHEN YEARS>5 AND YEARS<=10 THEN QTY ELSE 0 END ) AS '5-10(含)'
,SUM( CASE WHEN YEARS>10 AND YEARS<=15 THEN QTY ELSE 0 END ) AS '10-15(含)'
,SUM( CASE WHEN YEARS>15 AND YEARS<=20 THEN QTY ELSE 0 END ) AS '15-20(含)'
,SUM( CASE WHEN YEARS>20 THEN QTY ELSE 0 END ) AS '>20'
FROM (
SELECT  CONVERT(decimal(18,2), CONVERT(decimal(18,2), DATEDIFF(MONTH,COMMISSIONING_DATE,GETDATE()))/12) AS YEARS
,COUNT(1) AS QTY FROM [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
 WHERE  ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常' 
		  GROUP BY CONVERT(decimal(18,2), CONVERT(decimal(18,2), DATEDIFF(MONTH,COMMISSIONING_DATE,GETDATE()))/12)
		  ) A
		  ) T
		  --行转列
		  UNPIVOT
		  (
		  数量 FOR 投产年份 in([<=1],[1-3(含)],[3-5(含)],[5-10(含)],[10-15(含)],[15-20(含)],[>20])
		  ) P
	)t1
		 INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1  
	  )TT";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备状态
        public DataTable GetREPORT_STATE()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"SELECT TT.设备状态
,TT.数量
,concat(cast((TT.数量* 100.00 / total)as decimal(18,2)), '%') as '占比(%)'
,cast((convert(decimal(18,2),TT.数量) / convert(decimal(18,2),TT.total))as decimal(18,2)) as 占比
FROM (
SELECT *FROM (
SELECT * FROM (
SELECT 
SUM( CASE WHEN ISNULL(ONSITE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待引入'
,SUM( CASE WHEN ISNULL(ONSITE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待到厂'
,SUM( CASE WHEN ISNULL(DEBUGGING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待调试'
,SUM( CASE WHEN ISNULL(TRIAL_RUN_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待试产'
,SUM( CASE WHEN ISNULL(TRAINING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待培训'
,SUM( CASE WHEN ISNULL(ACCEPTANCE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待验收'
,SUM( CASE WHEN ISNULL(COMMISSIONING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待投产'
,SUM( CASE WHEN ISNULL(COMMISSIONING_DATE,'')!='' THEN 1 ELSE 0 END ) AS '设备已投产'
 FROM [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
 WHERE    ISNULL(ASSET_STATE,'') NOT IN ('报废','变卖')
		  ) T
		  --行转列
		  UNPIVOT
		  (
		  数量 FOR 设备状态 in([设备待引入],[设备待到厂],[设备待调试],[设备待试产],[设备待培训],[设备待验收],[设备待投产],[设备已投产])
		  ) P
	)t1
		 INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
           ISNULL(ASSET_STATE,'') NOT IN ('报废','变卖')
      ) t2 ON 1 = 1  
	  )TT";
                #region
                //            string sql = @"SELECT 设备状态
                //,SUM_QTY AS 数量
                //,cast((convert(decimal(18,2),SUM_QTY) / convert(decimal(18,2),total))as decimal(18,2)) as 占比 FROM (
                //SELECT A.设备状态,COUNT(1) AS SUM_QTY FROM (
                //SELECT CASE WHEN ISNULL(COMMISSIONING_DATE,'')!='' THEN '已验收'
                //WHEN ISNULL(MACHINE_APPLIED_NO,'')='' THEN '新设备待引入'
                //WHEN ISNULL(ONSITE_DATE,'')='' THEN '新设备待到厂'
                //WHEN ISNULL(DEBUGGING_DATE,'')='' THEN '新设备待调试'
                //WHEN ISNULL(TRIAL_RUN_DATE,'')='' THEN '新设备待试产'
                //WHEN ISNULL(TRAINING_DATE,'')='' THEN '新设备待培训'
                //WHEN ISNULL(ACCEPTANCE_DATE,'')='' THEN '新设备待验收'
                //ELSE NULL END AS 设备状态
                // FROM [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
                // WHERE  ISNULL(COMMISSIONING_DATE, '')!= '' 
                //          AND ASSET_STATE = '正常' )A
                //GROUP BY A.设备状态
                //  )t1
                //		 INNER JOIN(
                //        SELECT 
                //          COUNT(1) total 
                //        FROM 
                //          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
                //        WHERE 
                //          ISNULL(COMMISSIONING_DATE, '')!= '' 
                //          AND ASSET_STATE = '正常'
                //      ) t2 ON 1 = 1";
                #endregion
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备状态-待验收清单
        public DataTable GetREPORT_STATE_NoACCEPTANCE()
        {
            DataTable dt = new DataTable();
            string sql = @" SELECT MACHINE_NO AS 设备编号
      ,MACHINE_NAME AS 设备名称
	  ,CASE WHEN ISNULL(ONSITE_DATE,'')='' THEN '设备待引入'
                WHEN ISNULL(ONSITE_DATE,'')='' THEN '设备待到厂'
                WHEN ISNULL(DEBUGGING_DATE,'')='' THEN '设备待调试'
                WHEN ISNULL(TRIAL_RUN_DATE,'')='' THEN '设备待试产'
                WHEN ISNULL(TRAINING_DATE,'')='' THEN '设备待培训'
                WHEN ISNULL(ACCEPTANCE_DATE,'')='' THEN '设备待验收'
				WHEN ISNULL(COMMISSIONING_DATE,'')='' THEN '设备待投产'
                ELSE NULL END AS 设备状态
	   FROM  [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
	  WHERE ISNULL(COMMISSIONING_DATE, '')= ''
	  ORDER BY MACHINE_NO ";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        //设备状态-待验收清单明细
        public DataTable GetREPORT_STATE_Detail(string Machine_No)
        {
            DataTable dt = new DataTable();
            string sql = @"SELECT * FROM (
SELECT DE.MACHINE_NO AS 设备编号
      ,DE.MACHINE_NAME AS 设备名称
	 , FP.MACHINE_INFO_PATH AS 文件记录
	   FROM  [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize]  DE
	   JOIN [LamexMESManager].[dbo].[FAMA_File_Path_Info] FP ON DE.MACHINE_NO=FP.MACHINE_NO
	  WHERE ISNULL(DE.MACHINE_NO, '')= '" + Machine_No + @"'
	  UNION ALL
	  SELECT DE.MACHINE_NO AS 设备编号
      ,DE.MACHINE_NAME AS 设备名称
	 , FP.USE_RULES_PATH AS 文件记录
	   FROM  [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize]  DE
	   JOIN [LamexMESManager].[dbo].[FAMA_File_Path_Info] FP ON DE.MACHINE_NO=FP.MACHINE_NO
	  WHERE ISNULL(DE.MACHINE_NO, '')= '" + Machine_No + @"') A
	  WHERE ISNULL(A.文件记录,'')!=''";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        //设备状态-验收流程
        public DataTable GetREPORT_STATE_Flow()
        {
            DataTable dt = new DataTable();
            string sql = @"SELECT 
SUM( CASE WHEN ISNULL(ONSITE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待引入'
,SUM( CASE WHEN ISNULL(ONSITE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待到厂'
,SUM( CASE WHEN ISNULL(DEBUGGING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待调试'
,SUM( CASE WHEN ISNULL(TRIAL_RUN_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待试产'
,SUM( CASE WHEN ISNULL(TRAINING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待培训'
,SUM( CASE WHEN ISNULL(ACCEPTANCE_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待验收'
,SUM( CASE WHEN ISNULL(COMMISSIONING_DATE,'')='' THEN 1 ELSE 0 END ) AS '设备待投产'
,SUM( CASE WHEN ISNULL(COMMISSIONING_DATE,'')!='' THEN 1 ELSE 0 END ) AS '设备已投产'
 FROM [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
 WHERE   ISNULL(ASSET_STATE,'') NOT IN ('报废','变卖')";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

        //盘点结果
        public DataTable GetMachine_Inventory()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"SELECT 
INVENTORY_RESULT AS 设备状态
,SUM_QTY AS 数量
,concat(cast((SUM_QTY* 100.00 / total)as decimal(18,2)), '%') as '占比(%)'
,cast((convert(decimal(18,2),SUM_QTY) / convert(decimal(18,2),total))as decimal(18,2)) as 占比
 FROM(
SELECT INVENTORY_RESULT,COUNT(1) AS SUM_QTY FROM [dbo].[FAMA_Account_Stocktake_Record] R JOIN 
[LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize]  I ON R.MACHINE_NO=I.MACHINE_NO
WHERE ISNULL(I.COMMISSIONING_DATE, '')!= '' 
          AND I.ASSET_STATE = '正常'
		  GROUP BY INVENTORY_RESULT
		  	  )t1
		 INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
         ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备产地
        public DataTable GetMachine_Origin()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @"SELECT 
  MACHINE_ORIGIN as 设备产地, 
  SUM_QTY as 数量,
concat(cast((SUM_QTY* 100.00 / total)as decimal(18,2)), '%') as '占比(%)',
  cast((convert(decimal(18,2),SUM_QTY) / convert(decimal(18,2),total))as decimal(18,2)) as 占比
FROM 
  (
    SELECT 
      * 
    FROM 
      (
        SELECT 
          MACHINE_ORIGIN, 
          COUNT(1) AS SUM_QTY 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常' 
        GROUP BY 
          MACHINE_ORIGIN
      ) t1 
      INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1
  ) t";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备折旧
        public DataTable GetMachine_Depre()
        {
            DataTable dt = new DataTable();
            //先进行判断，避免除数为0
            if (flag)
            {
                string sql = @" SELECT TT.设备状态
,TT.数量
,cast((convert(decimal(18,2),TT.数量) / convert(decimal(18,2),TT.total))as decimal(18,2)) as '占比(%)'
,concat(cast((TT.数量* 100.00 / total)as decimal(18,2)), '%') as 占比
FROM (
SELECT *FROM (
SELECT * FROM(
SELECT COUNT(CASE WHEN YEARS<=DURABLE_YEARS THEN 1 ELSE NULL END) AS '在折旧期间'
,COUNT(CASE WHEN YEARS>DURABLE_YEARS THEN 1 ELSE NULL END) AS '已过折旧期'
FROM(
SELECT  datediff(year, COMMISSIONING_DATE,CONVERT(varchar(10),GETDATE(),120)) AS YEARS
,DURABLE_YEARS
 FROM [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
 WHERE  ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常' )A
		 )  T
		  --行转列
		  UNPIVOT
		  (
		  数量 FOR 设备状态 in([在折旧期间],[已过折旧期])
		  ) P
		  )t1
		 INNER JOIN(
        SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'
      ) t2 ON 1 = 1  
	  )TT";
                dt = BaseBuildSql.GetDataTableBySql(sql);
            }
            return dt;
        }
        //设备折旧-已过折旧期
        public DataTable GetMachine_Depre_Over()
        {
            DataTable dt = new DataTable();
            string sql = @"SELECT DE.MACHINE_NO as '设备编号'
      ,DE.MACHINE_NAME as '设备名称'	  
	  ,'已过折旧期' as '当前状况'
	  ,CASE WHEN  FP.MACHINE_INFO_PATH LIKE '%折旧超限说明%' THEN FP.MACHINE_INFO_PATH ELSE '' END as'改善说明' 
	  FROM   [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] DE
	  LEFT JOIN [LamexMESManager].[dbo].[FAMA_File_Path_Info] FP ON DE.MACHINE_NO=FP.MACHINE_NO  AND FP.MACHINE_INFO_PATH LIKE '%折旧超限说明%'
	  WHERE datediff(year, COMMISSIONING_DATE,CONVERT(varchar(10),GETDATE(),120))>DURABLE_YEARS
	  AND   ISNULL(COMMISSIONING_DATE, '')!= '' AND ASSET_STATE = '正常'
	  ORDER BY DE.MACHINE_NO";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

        //获取设备状态为正常的总数
        public DataTable GetMachine_SumQty()
        {
            DataTable dt = new DataTable();
            string sql = @"SELECT 
          COUNT(1) total 
        FROM 
          [LamexMESManager].[dbo].[View_FAMA_Equipment_Account_Sumarize] 
        WHERE 
          ISNULL(COMMISSIONING_DATE, '')!= '' 
          AND ASSET_STATE = '正常'";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

        //取得设备下拉框选择值
        public DataTable GetValuesOption()
        {
            DataTable dt = new DataTable();
            string sql = @"SELECT  VALUE_NAME,[VALUE_OPTION]
  FROM [LamexMESManager].[dbo].[FAMA_Account_ValueOption]
  WHERE IS_DISABLE=0 ";
            dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

        //设备维修-查询设备编号
        public static DataTable GetTable_Machine()
        {
            string sql = @"  SELECT[MACHINE_NO],[MACHINE_DESC] FROM[LamexMESManager].[dbo].[FAMA_Account_Basic_Info]";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        //设备维修-查询维修人信息
        public static DataTable GetTable_RepairMan()
        {
            string sql = @"SELECT [WORKER_NO]
      ,[WORKER_NAME]
      ,[DEPARTMENT]
      ,[PHONE_NO]
      ,[MAILBOX]
      ,[REPORT_FLAG]
      ,[MAINTAIN_FLAG]
      ,[CONFIRM_FLAG]
  FROM [LamexMES_FAMA].[dbo].[MT_Resource_Worker_List]";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        //设备维修-按条件查询维修人信息
        public static DataTable GetTable_ReportMan_WorkerNo(string WorkerNo)
        {
            string sql = @"SELECT [WORKER_NO]
      ,[WORKER_NAME]
      ,[DEPARTMENT]
      ,[PHONE_NO]
      ,[MAILBOX]
      ,[REPORT_FLAG]
      ,[MAINTAIN_FLAG]
      ,[CONFIRM_FLAG]
  FROM [LamexMES_FAMA].[dbo].[MT_Resource_Worker_List] WHERE WORKER_NO='" + WorkerNo + "' AND ISNULL(REPORT_FLAG,'')='1'";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        public static DataTable GetTable_RepairMan_WorkerNo(string WorkerNo)
        {
            string sql = @"SELECT [WORKER_NO]
      ,[WORKER_NAME]
      ,[DEPARTMENT]
      ,[PHONE_NO]
      ,[MAILBOX]
      ,[REPORT_FLAG]
      ,[MAINTAIN_FLAG]
      ,[CONFIRM_FLAG]
  FROM [LamexMES_FAMA].[dbo].[MT_Resource_Worker_List] WHERE WORKER_NO='" + WorkerNo + "' AND ISNULL(MAINTAIN_FLAG,'')='1'";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }
        public static DataTable GetTable_ConfirmMan_WorkerNo(string WorkerNo)
        {
            string sql = @"SELECT [WORKER_NO]
      ,[WORKER_NAME]
      ,[DEPARTMENT]
      ,[PHONE_NO]
      ,[MAILBOX]
      ,[REPORT_FLAG]
      ,[MAINTAIN_FLAG]
      ,[CONFIRM_FLAG]
  FROM [LamexMES_FAMA].[dbo].[MT_Resource_Worker_List] WHERE WORKER_NO='" + WorkerNo + "' AND ISNULL(CONFIRM_FLAG,'')='1'";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

        //设备维修-获取故障类别
        public static string GetArray_Type()
        {
            string list="";
            string sql = @"SELECT[FIELD_VALUE_OPTION] FROM [LamexMESManager].[dbo].[Sys_ControlValueOption] WHERE FIELD_NAME = 'FAMA_MT_FAILURE_TYPE'";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            if (dt.Rows.Count > 0)
                list = dt.Rows[0]["FIELD_VALUE_OPTION"].ToString();
            return list;
        }
        //设备维修-内部维修获取实际故障类别
        public static string GetArray_ActualType()
        {
            string list = "";
            string sql = @"SELECT[FIELD_VALUE_OPTION] FROM [LamexMESManager].[dbo].[Sys_ControlValueOption] WHERE FIELD_NAME = 'FAMA_MT_FAILURE_ACTUALTYPE'";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            if (dt.Rows.Count > 0)
                list = dt.Rows[0]["FIELD_VALUE_OPTION"].ToString();
            return list;
        }
        //设备维修-委外维修编号
        public static DataTable GetTable_Outsource()
        {
            string sql = @"  SELECT MAINTAIN_NO, mr.MACHINE_NO,bi.MACHINE_DESC,PROCESS_PLAN
             FROM[LamexMES_FAMA].[dbo].[MT_Maintain_Record] mr,
            [LamexMESManager].[dbo].[FAMA_Account_Basic_Info] bi
            WHERE mr.MACHINE_NO = bi.MACHINE_NO
            AND PROCESS_PLAN = '委外维修' AND CONFIRM_PERSON IS NULL";
            DataTable dt = BaseBuildSql.GetDataTableBySql(sql);
            return dt;
        }

    }
}
